const {Sequelize, DataTypes} = require("sequelize");

const sequelize = new Sequelize({
  dialect: "mysql",
  host: "localhost",
  port: 3306,
  username: "root",
  password: "123456",
  database: "OrderingSystem",
  timezone: "+08:00", // 也可以直接使用这种方式设置时区
});

// 检查并创建数据库
sequelize
  .query(`CREATE DATABASE IF NOT EXISTS OrderingSystem;`)
  .then(() => {
    console.log("Database is ready.");
    // 连接到数据库
    return sequelize.authenticate();
  })
  .then(() => {
    console.log("Connection has been established successfully.");
  })
  .catch((err) => {
    console.error("Unable to connect to the database:", err);
  });

module.exports = {sequelize, DataTypes};
